<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@page import="java.util.*"%>
<%@page import="java.net.URLEncoder"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查看购物车</title>
</head>
<body>
	<%
		Map<String, Integer> cart = (HashMap<String, Integer>) session.getAttribute("cart");
		if (cart != null && cart.size() > 0) {
	%>

	<table border="1">
		<thead>
			<tr>
				<td>名称</td>
				<td>价格</td>
				<td>功能</td>
			</tr>

		</thead>

		<tbody>

			<%
				Set<String> keyset = cart.keySet();
					Iterator<String> it = keyset.iterator();
					String name, encodedUrl;
					Integer price;
					while (it.hasNext()) {
						name = it.next();
						price = cart.get(name);
						encodedUrl = URLEncoder.encode(name, "UTF-8"); // 进行url编码
			%>
			<tr>
				<td><%=name%></td>
				<td><%=price%></td>
				<td><a href="delete_cart.jsp?name=<%=encodedUrl%>">删除</a></td>
			</tr>


			<%
				}
			%>

		</tbody>
	</table>

	<%
		} else {
			out.print("购物车空空如也。");
		}
	%>
</body>
</html>